package org.liuyuantao.patterns.singleton;

/**
 * 俗称双重检查锁定,在JDK1.5之后,双重检查锁定才能够正常达到单例效果
 */
public class Singleton04 {
    private volatile static Singleton04 singleton = null;

    private Singleton04() {
        System.out.println("创建了Singleton04实例!");
    }

    public static Singleton04 getSingleton() {
        if (singleton == null) {
            synchronized (Singleton04.class) {
                if (singleton == null) {
                    singleton = new Singleton04();
                }
                return singleton;
            }
        }
        return singleton;
    }
}
